package com.yexiao.cofe.business.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yexiao.cofe.business.pojo.Order;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author lkl
 * @since 2025/3/28
 */
@Mapper
public interface OrderMapper extends BaseMapper<Order> {

    // 乐观锁
    @Update("update `order` set `status` = #{newStatus} where order_id = #{orderId} and `status` = #{oldStatus}")
    void modifyStatus(@Param("orderId") Long orderId, @Param("oldStatus") int oldStatus, @Param("newStatus") int newStatus);

    @Select("select * from `order` where order_id = #{orderId}")
    Order selectByOrderId(Long orderId);

    @Select("select * from `order` where user_id = #{userId} order by create_time desc")
    List<Order> listByUserId(String userId);

    @Select("select * from `order` where store_id = #{storeId} order by create_time desc")
    List<Order> listByStoreId(String storeId);

    @Update("update `order` set pickup_code = #{pickCode} where order_id = #{orderId}")
    void setPickCode(@Param("orderId") Long orderId, @Param("pickCode") String pickCode);
}
